package com.weixing.mall.provider.controller.rpc;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.provider.api.model.vo.SealMatchRuleVo;
import com.weixing.mall.provider.api.model.vo.dto.DepotRPcVo;
import com.weixing.mall.provider.model.domain.Depot;
import com.weixing.mall.provider.model.domain.SealMatchRule;
import com.weixing.mall.provider.service.IDepotService;
import com.weixing.mall.provider.service.ISealMatchRuleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author wx
 * @Date 2019/12/5 16:47
 * @Version 1.0
 */
@RestController
@RequestMapping("api/sealMathRule")
public class SealMathRuleRpcController {

    @Autowired
    private ISealMatchRuleService sealMatchRuleService;
    @Autowired
    private IDepotService depotService;

    @GetMapping("getById")
    public Result<SealMatchRuleVo> getById(Long id){
        SealMatchRuleVo sealMatchRuleVo = new SealMatchRuleVo();
        SealMatchRule sealMatchRule = sealMatchRuleService.getById(id);
        if(null!=sealMatchRule.getFirstMatch()){
            Depot depot= depotService.getById(sealMatchRule.getFirstMatch());
            if(depot!=null){
                DepotRPcVo vo=new DepotRPcVo();
                BeanUtils.copyProperties(depot,vo);
                sealMatchRuleVo.setFirstDepot(vo);
            }

        }
        if(null!=sealMatchRule.getSecondMatch()){
            Depot depot=depotService.getById(sealMatchRule.getSecondMatch());
            if(depot!=null){
                DepotRPcVo vo=new DepotRPcVo();
                BeanUtils.copyProperties(depot,vo);
                sealMatchRuleVo.setSecodeDpot(vo);
            }

        }
        if(null!=sealMatchRule.getThirdMatch()){
            Depot depot=depotService.getById(sealMatchRule.getThirdMatch());
            if(depot!=null){
                DepotRPcVo vo=new DepotRPcVo();
                BeanUtils.copyProperties(depot,vo);
                sealMatchRuleVo.setThridDepot(vo);
            }

        }
        if(sealMatchRule!=null){
            BeanUtils.copyProperties(sealMatchRule,sealMatchRuleVo);
        }
        return ResultUtil.success(sealMatchRuleVo);
    }
}
